﻿using Microsoft.VisualStudio.Modeling;
using System.Windows.Forms;

namespace Project.Co_DataTransformationPrototype
{
    /// <summary>
    /// Utility class for counting diagram elements
    /// </summary>
    public static class ElementCounter
    {
        /// <summary>
        /// Displays a message box with the stats on the number of entities, attributes and links in the current diagram
        /// </summary>
        /// <param name="store">The current model's store object</param>
        internal static void getElementCount(Store store)
        {
            int countLinks = 0; 
            int countEntities = 0;
            int countAttributes = 0;

            if (store != null)
            {
                foreach (Entity ent in store.ElementDirectory.FindElements<Entity>())
                {
                    countEntities++;
                    countLinks += ent.Targets.Count;
                    countAttributes += ent.EntityAttributes.Count;
                }
                MessageBox.Show(string.Format("Number of entities: {0}. Nr of attributes: {1}. Nr of links: {2}", countEntities, countAttributes, countLinks));
            }
            else
            {
                MessageBox.Show("Diagram store was empty", "Model Element Counter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
